package com.sch.study.concurrency.baseThread;

/**
 * User: hui_stone
 * Date: 2016/2/25 0025
 * Time: 上午 11:24
 */
public class SleepLockTest {

    private static Object obj = new Object();

    public static void main(String[] args) throws InterruptedException {
        ThreadA t1 = new ThreadA("t1");
        ThreadA t2 = new ThreadA("t2");
        t1.start();
        //t2.start();
        //Thread.sleep(1000);
        System.out.println("main Thread is runing.....");
    }

    static class ThreadA extends Thread{
        public ThreadA(String name){
            super(name);
        }
        public void run(){
            // 获取obj对象的同步锁
            synchronized (obj) {
                try {
                for(int i=0; i <10; i++){
                      System.out.printf("%s: %d\n", this.getName(), i);
                      // i能被4整除时，休眠100毫秒
                      if (i%4 == 0)
                            Thread.sleep(1000);
                  }
                } catch (InterruptedException e) {
                    e.printStackTrace();
               }
            }
        }
     }
}
